#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=110;
const LL INF=0x3f3f3f3f3f3f3f3f;
int t;
int n;
int a[N];
LL f[N][N][N];
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
        }
        memset(f,0xcf,sizeof f);
        f[0][0][0]=0;
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<=i;j++)
            {
                for(int k=0;k<=i;k++)
                {
                    if(j&&j==k)
                    {
                        continue;
                    }
                    if(j&&a[i+1]==a[j])
                    {
                        f[i+1][i+1][k]=max(f[i+1][i+1][k],f[i][j][k]+a[i+1]);
                    }
                    else
                    {
                        f[i+1][i+1][k]=max(f[i+1][i+1][k],f[i][j][k]);
                    }
                    if(k&&a[i+1]==a[k])
                    {
                        f[i+1][j][i+1]=max(f[i+1][j][i+1],f[i][j][k]+a[i+1]);
                    }
                    else
                    {
                        f[i+1][j][i+1]=max(f[i+1][j][i+1],f[i][j][k]);
                    }
                }
            }
        }
        LL res=-INF;
        for(int i=0;i<=n;i++)
        {
            for(int j=0;j<=n;j++)
            {
                if(i==j)
                {
                    continue;
                }
                res=max(res,f[n][i][j]);
            }
        }
        printf("%lld\n",res);
    }
    return 0;
}
